#include<iostream>
using namespace std;
#include<string.h>
//string 作为C++处理字符串的 类 ，经过重载运算符和添加成员函数，是的C++操作字符串更方便了。

int main()
{

    string str;
    str = "you are a dog";

    //find 查找字符 返回下标
    int flag1 = str.find('a',0);
    int flag2 = str.find("are",0);
    cout<<flag1<<"  "<<flag2<<endl;
    
    //str.size() 
    cout<<"size: "<<str.size()<<endl;

    // string 下标访问
    cout<<str[5]<<endl;

    //erase
    str.erase(1,5);

    //char *p = c_str();
    const char *p = str.c_str();
    cout<<p<<endl;
    char buf[1024];
    strcpy(buf,str.c_str());
    cout<<buf<<endl;
    cout<<buf[3]<<endl;

    //swap
    string s1 = "xxxxx";
    string s2 = "aaaaa";
    cout<<"s1: "<<s1<<"  s2: "<<"s1: "<<s2<<endl;
    s1.swap(s2);
    cout<<"s1: "<<s1<<"  s2: "<<"s1: "<<s2<<endl;
    return 0;
}